package cn.ziroom.webservice;

import javax.jws.WebMethod;
import javax.jws.WebService;

import cn.ziroom.contract.data.PayData;
import cn.ziroom.contract.data.VoucherOrder;
import cn.ziroom.contract.service.PayPlanService;
import cn.ziroom.system.domain.Message;
import cn.ziroom.system.service.MessageService;

@WebService(serviceName = "pay", name = "pay")
public class ZiruPayPlanInterface {

	private PayPlanService payPlanService;

	private MessageService messageService;

	/**
	 * 同步合同收付款计划
	 * 
	 * @param payData
	 * @return
	 */
	@WebMethod
	public String payPlan(PayData payData) {
		String ret = payPlanService.synchroPayPlan(payData);

		Message msg = new Message();
		msg.setFunctionName("payPlan");

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);
		return ret;
	}

	/**
	 * 同步合同收付款单
	 * 
	 * @param payData
	 * @return
	 */
	@WebMethod
	public String voucherContract(VoucherOrder voucherOrder) {
		String ret = payPlanService.synchroVoucherContract(voucherOrder);
		Message msg = new Message();
		msg.setFunctionName("payPlan");

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);
		return ret;
	}
	
	/**
	 * 同步合同收付款单全量
	 * 
	 * @param payData
	 * @return
	 
	@WebMethod
	public String voucherContractAll(VoucherOrder voucherOrder) {
		String ret = payPlanService.synchroVoucherContractAll(voucherOrder);
		Message msg = new Message();
		msg.setFunctionName("payPlan");

		// 根据返回值来形成日志信息
		if (ret != null && ret.indexOf("_") > 0) {
			msg.setStatus(ret.substring(0, ret.indexOf("_")));
			msg.setJson(ret.substring(ret.indexOf("_") + 1));
		} else {
			msg.setStatus(ret);
		}

		messageService.insert(msg);
		return ret;
	}
	 */
	public void setPayPlanService(PayPlanService payPlanService) {
		this.payPlanService = payPlanService;
	}

	public void setMessageService(MessageService messageService) {
		this.messageService = messageService;
	}
}
